<template>
  <vxe-modal v-model="modalVisible" ref="xModal" :title="title" width="600" resize remember>
    <template>
      <vxe-form
          ref="xForm"
          class="data-form"
          title-align="right"
          title-width="60"
          :data="formData"
          :rules="formRules"
          @submit="submitEvent">
        <vxe-form-item title="指派" field="Type" span="24">
          <vxe-select v-model="formData.Type" placeholder="指派类型">
            <vxe-option :key="1" :value="1" :label="`指派人`"></vxe-option>
            <vxe-option :key="2" :value="2" :label="`指派部门`"></vxe-option>
          </vxe-select>
        </vxe-form-item>
        <vxe-form-item v-if="formData.Type===1" title="姓名" field="Acceptid" span="24">
          <template v-slot="scope">
            <select-project-team v-model="formData.Acceptid" placeholder="请选择指派人"></select-project-team>
          </template>
        </vxe-form-item>

        <vxe-form-item v-if="formData.Type===2" title="部门" field="Uatdepart" span="24">
          <template v-slot="scope">
            <select-depart v-model="formData.Uatdepart" placeholder="请选择验收部门"></select-depart>
          </template>
        </vxe-form-item>

        <vxe-form-item title="描述" field="note" span="24" >
          <vxe-textarea v-model="formData.note" :autosize="{minRows: 4}"></vxe-textarea>
        </vxe-form-item>
        <vxe-form-item span="24" align="center">
          <template v-slot>
            <el-button type="primary" native-type="submit">确定</el-button>
            <el-button @click="modalVisible = false">关闭</el-button>
          </template>
        </vxe-form-item>
      </vxe-form>
    </template>
  </vxe-modal>
</template>

<script>
import SelectProjectTeam from "@/components/element/select/SelectProjectTeam";
import SelectDepart from "@/components/element/select/SelectDepart";
import projectTestApi from "@/api/projectTestApi";
export default {
  components: {
    SelectProjectTeam,
    SelectDepart
  },
  props: {
    formData: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      require: true
    }
  },
  computed: {
    modalVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  watch: {
    visible: {
      handler (n, o) {
        if (n) {
          this.$set(this.formData, 'Type', 1)
        }
      }
    }
  },
  data () {
    return {
      Type: 1,
      formRules: {
        Type: [{required: true, message: '请选择反馈类型'}],
        Acceptid: [{required: true, message: '请选择指派人员'}],
        Uatdepart: [{required: true, message: '请选择指派验收部门'}]
      }
    }
  },
  methods: {
    submitEvent () {
      this.formData.id = this.formData.Id
      projectTestApi.accept(this.formData).then(res => {
        this.$XModal.message({message: res.message, status: res.code === 1 ? 'success' : 'error'})
        this.$emit('search')
        if (res.code === 1) this.modalVisible = false
      })
    }
  }
}
</script>

<style>

</style>